﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BloomsburyBanHang.DTO
{
    public class TaiLieuDTO
    {
        public int MaTaiLieu;






        public string TacGia;



        public string NhaXuatBan;


        public double GiaBia;



        public double GiaGoc;


        public int SoLuong;

        public string TenTaiLieu;


        public string TenLinhVuc;

        public string TenLoaiTaiLieu;



        public int TinhTrang;

        int hard_Soft; //Tài liệu là hardcopCy hay softcopy

        public int Hard_Soft;


        public DateTime NgayPhatHanh;


        public List<ThuocTinhTaiLieuDTO> DsThuocTinh;

        public static TaiLieuDTO Convert(SAN_PHAM sp)
        {
            TaiLieuDTO result = new TaiLieuDTO();
            result.GiaBia = (double)sp.Gia;
            result.GiaGoc = (double)sp.Gia;
            result.MaTaiLieu = 0;
            result.NgayPhatHanh = DateTime.Now;
            result.TenLinhVuc = sp.THE_LOAI.TenTheLoai;
            result.TinhTrang = 0;
            result.Hard_Soft = 1;
            result.SoLuong = (int)sp.SoLuongTon;
            result.NhaXuatBan = "BloomBury";
          
            result.TenTaiLieu = sp.TenSanPham;
            ThuocTinhTaiLieuDTO tt = new ThuocTinhTaiLieuDTO();
            tt.TenThuocTinh = "Mo ta";
            tt.GiaTri = sp.MoTa;
            List<ThuocTinhTaiLieuDTO> listThuocTinh = new List<ThuocTinhTaiLieuDTO>();
            listThuocTinh.Add(tt);
            result.DsThuocTinh = listThuocTinh;
            return result;
        }
        public static SAN_PHAM ReserveConvert(TaiLieuDTO tl)
        {
            SAN_PHAM sp = new SAN_PHAM();
            sp.Gia = tl.GiaBia;
            sp.Gia = tl.GiaGoc;
            sp.TenSanPham = tl.TenTaiLieu;
            sp.SoLuongTon = tl.SoLuong;
            sp.NgayPhatHanh = tl.NgayPhatHanh;
            foreach (ThuocTinhTaiLieuDTO i in tl.DsThuocTinh)
            {
                sp.MoTa += i.TenThuocTinh + " :" + i.GiaTri;
            }
            return sp;
        }
        public static List<TaiLieuDTO> ListConvert(List<SAN_PHAM> lstSP)
        {
            List<TaiLieuDTO> listResult = new List<TaiLieuDTO>();
            for (int i = 0; i < lstSP.Count; i++)
            {
                listResult.Add(Convert(lstSP[i]));
            }
            return listResult;
        }
        public static List<SAN_PHAM> ListReverseConvert(List<TaiLieuDTO> lstSP)
        {
            List<SAN_PHAM> listResult = new List<SAN_PHAM>();
            for (int i = 0; i < lstSP.Count; i++)
            {
                listResult.Add(ReserveConvert(lstSP[i]));
            }
            return listResult;
        }

    }
}